package com.hbnu.zhouxunfa;


import java.io.*;
import java.net.Socket;

public class FileClient {
    public static void main(String[] args) {
        File file = new File("Websocaket\\clientdir\\test.txt");
        try {
            Socket socket = new Socket("127.0.0.1",8080);
            OutputStream os = socket.getOutputStream();
            FileInputStream fis = new FileInputStream(file);
            byte[] bytes = new byte[1024];
            int len;
            int index = 0;
            while ((len = fis.read())!=-1){
                bytes[index++] = (byte) len;
                os.write(len);
            }
            System.out.println("客户端打印读取文件的内容："+new String(bytes,0,index));

            socket.shutdownOutput();

            //接收回显数据
            InputStream is = socket.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            int lens;
            while ((lens = isr.read())!=-1){
                System.out.print((char) lens);
            }

            socket.close();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
